<template>
  <div class="trains">
    <swiper :imgList="imgList"></swiper>
    <van-tabs v-model="active" swipeable>
      <van-tab v-for="item in tabTitleData" :title="item.catename">
        <div class="content-list" v-for="item in tabContentArr" @click="train(item.id)">
          <div class="left">
            <img :src="item.pic"/>
          </div>
          <div class="right">
            <p class="right-title">{{item.title}}</p>
            <p class="right-desc">{{item.content.substring(0,40)}}</p>
            <p class="right-bottom">
              <span class="right-btn">培训</span>
            </p>
          </div>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
  import Swiper from '@/components/swiper/Swiper'
  import {config, _isPhoneNumber} from '@/util/config'
  import axios from 'axios'

  export default {
    name: "trains",
    data() {
      return {
        id: 0,
        imgList: [],
        active: 1,
        trainList: [],
        tabContentArr: [],
        tabTitleData: [],
        cateid: "",
        cur: 0,
      };
    },
    components: {Swiper,},
    mounted() {
      this.getswiperInfo('/api/trainlist/banner', config.memberid);
      this.getclassInfo('/api/traincate', config.memberid);
    },

    methods: {
      train(id) {
        this.$router.push({name: 'trainDetail', params: {id: id}})
      },
      // 轮播数据加载
      getswiperInfo(url, memberid) {
        let that = this
        axios.post(url, {
          'memberid': memberid,
        }).then((res) => {
          that.imgList = res.data.data
        })
      },
      // 轮播数据加载
      getclassInfo(url, memberid) {
        let that = this
        axios.get(url, {
          'memberid': memberid,
        }).then((res) => {
            that.tabTitleData = res.data.data;
            this._gettrainList(memberid, res.data.data[0].id, 0)
          }
        )
      },
      _gettrainList(memberid, cateid, cur) {
        let that = this
        axios.get('/api/trainlist', {
          'cateid': cateid,
          'memberid': memberid,
        }).then((res) => {
            this.tabContentArr = res.data.data
          }
        )
      },
    },

  }
</script>

<style scoped lang="less">

  .trains {
    font-size: 14px;
    .content-list {
      border-top: 1px solid #f5f5fa;
      padding: 10px;
      display: flex;
      .left {
        width: 130px;
        height: 90px;
        position: relative;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .right {
        position: relative;
        text-align: left;
        padding: 6px 0 6px 8px;
        flex: 1;
        .right-title {
          font-weight: bold;
          padding-bottom: 4px;
        }
        .right-desc {
          font-size: 12px;
          color: #666;
        }
        .right-bottom {
          position: absolute;
          bottom: 0;
          right: 0;
          .right-btn {
            background: #ffac66;
            border-radius: 3px;
            color: #fff;
            text-align: center;
            font-size: 12px;
            font-weight: 500;
            margin-top: 8px;
            padding: 2px 12px 2px 12px;
          }
        }
      }
    }

  }
</style>
